home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / src-server / w_XmString.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-04  |  30.4 KB  |  826 lines

  1. /* -*-C-*-
  2. ********************************************************************************
  3. *
  4. * File:         w_XmString.c
  5. * RCS:          $Header: w_XmString.c,v 1.6 91/03/14 03:13:22 mayer Exp $
  6. * Description:  Interfaces to XmString routines
  7. * Author:       Niels Mayer, HPLabs
  8. * Created:      Sun Nov  5 14:46:20 1989
  9. * Modified:     Thu Oct  3 23:40:04 1991 (Niels Mayer) mayer@hplnpm
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       X11r5 contrib tape release
  13. *
  14. * WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. * XLISP version 2.1, Copyright (c) 1989, by David Betz.
  16. *
  17. * Permission to use, copy, modify, distribute, and sell this software and its
  18. * documentation for any purpose is hereby granted without fee, provided that
  19. * the above copyright notice appear in all copies and that both that
  20. * copyright notice and this permission notice appear in supporting
  21. * documentation, and that the name of Hewlett-Packard and David Betz not be
  22. * used in advertising or publicity pertaining to distribution of the software
  23. * without specific, written prior permission.  Hewlett-Packard and David Betz
  24. * make no representations about the suitability of this software for any
  25. * purpose. It is provided "as is" without express or implied warranty.
  26. *
  27. * HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  28. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  29. * IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  30. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  31. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  32. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  33. * PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * See ./winterp/COPYRIGHT for information on contacting the authors.
  36. * Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  37. * Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  38. *
  39. ********************************************************************************
  40. */
  41. static char rcs_identity[] = "@(#)$Header: w_XmString.c,v 1.6 91/03/14 03:13:22 mayer Exp $";
  42.  
  43. #include <stdio.h>
  44. #include <Xm/Xm.h>
  45. #include "winterp.h"
  46. #include "user_prefs.h"
  47. #include "xlisp/xlisp.h"
  48. #include "w_XmString.h"
  49.  
  50. static LVAL s_XmSTRING_DIRECTION_L_TO_R, s_XmSTRING_DIRECTION_R_TO_L; /* init'd in Wxms_Init() */
  51.  
  52. /******************************************************************************
  53.  *
  54.  ******************************************************************************/
  55. void Wxms_Garbage_Collect_XmString(lval_xmstring)
  56.      LVAL lval_xmstring;
  57. {
  58.   XmStringFree(get_xmstring(lval_xmstring));
  59. }
  60.  
  61.  
  62. /******************************************************************************
  63.  * the XmStrings created here will be freed when the lisp vector holding
  64.  * the XmStrings gets garbage collected and  there are no more references
  65.  * to the XmStrings.
  66.  ******************************************************************************/
  67. LVAL Wxms_XmStringTable_To_Lisp_Vector(xmstrtab, size)
  68.      XmStringTable xmstrtab;
  69.      int           size;
  70. {
  71.   LVAL result;
  72.   int i;
  73.   
  74.   if (!xmstrtab || !size)
  75.     return (NIL);
  76.  
  77.   xlsave1(result);
  78.   result = newvector(size);
  79.   for (i = 0; i < size; i++)
  80.     setelement(result, i, cv_xmstring(XmStringCopy(xmstrtab[i])));
  81.   xlpop();
  82.   return (result);
  83. }
  84.  
  85.  
  86. /******************************************************************************
  87.  * This is equivalent to an xlga*() function, in that it retrieves an argument
  88.  * of a certain type from the argument stack. This particular xlga*() function
  89.  * will retrieve a String OR XmString argument to an XLISP function. If the
  90.  * argument was a string, it will convert it to an XmString and return that,
  91.  * otherwise it returns the XmString-value of the argument.
  92.  *
  93.  * In calling this function, you must pass it a pointer to an LVAL in which
  94.  * this function will store a lisp-node of type XLTYPE_XmString. If this 
  95.  * function ended up converting a string to an XmString, that XmString will be
  96.  * garbage collected unless it is explicitly saved by code in the calling function.
  97.  * In many cases, this fn. is used in methods that return the XLTYPE_XmString
  98.  * node, in which case the XLTYPE_XmString won't be garbage collected if it
  99.  * is referenced in the user's lisp code.
  100.  ******************************************************************************/
  101. XmString Get_String_or_XmString_Arg_Returning_XmString(item)
  102.      LVAL *item;        /* param to return an LVAL_XmString */
  103. {
  104.   XmString result;
  105.   LVAL arg = xlgetarg();
  106.  
  107.   if (xmstring_p(arg)) {
  108.     *item = arg;
  109.     return (get_xmstring(arg));
  110.   }
  111.   else if (stringp(arg)) {
  112.     result = XmStringCreate(getstring(arg), XmSTRING_DEFAULT_CHARSET);
  113.     *item = cv_xmstring(result); /* note that the XmString created  will get g.c'd if not ref'd */
  114.     return (result);
  115.   }
  116.   else
  117.     xlerror("Bad type: expected either a XmString or a string.", arg);
  118. }
  119.  
  120.  
  121. /******************************************************************************
  122.  * Wxms_Cvt_LispStringSequence_to_SuperXmStringTable() converts it's LVAL argument
  123.  * and returns a SuperXmStringTable. The LVAL is a sequence (list or array) of
  124.  * String(s) OR XmString(s).
  125.  * If the sequence element was a string, this routine will automatically convert it
  126.  * to an XmString. Thus this routine will return a SuperXmStringTable object, which
  127.  * contains the XmStringTable representing the LVAL.
  128.  *
  129.  * You MUST call Wxms_Free_SuperXmStringTable() after calling this function and after
  130.  * the SuperXmStringTable result of this function is no longer being used.
  131.  * The cleanup function will deallocate any automatically converted XmStrings.
  132.  ******************************************************************************/
  133.  
  134. #define XMSTRINGTABLE_SIZE_INCREMENT 50
  135. #define FREEABLES_SIZE_INCREMENT 50
  136.  
  137. static SuperXmStringTable New_SuperXmStringTable(size)
  138.      int size;
  139. {
  140.   SuperXmStringTable superstrtab = (SuperXmStringTable) XtMalloc((unsigned) sizeof(struct _SuperXmStringTable));
  141.   superstrtab->xmstrtab = (XmString *) XtMalloc((unsigned) (size * sizeof(XmString)));
  142.   superstrtab->freeables = NULL;
  143.   return (superstrtab);
  144. }
  145.  
  146. void Wxms_Free_SuperXmStringTable(superstrtab)
  147.      SuperXmStringTable superstrtab;
  148. {
  149.   /*
  150.    * deallocate stuff declared as freeable by SuperXmStringTable_Declare_Temporary_Storage()
  151.    */
  152.   register int i, freeables_end_idx;
  153.   Deallocator_Pair* freeables;
  154.  
  155.   if (superstrtab->freeables) {
  156.     freeables = superstrtab->freeables;
  157.     freeables_end_idx = superstrtab->freeables_end_idx;
  158.     for (i = 0 ; i < freeables_end_idx ; i++)
  159.       (*(freeables[i].deallocator))(freeables[i].pointer);
  160.     XtFree(superstrtab->freeables);
  161.   }
  162.  
  163.   /*
  164.    * Free the XmStringTable
  165.    */
  166.   if (superstrtab->xmstrtab)
  167.     XtFree(superstrtab->xmstrtab);
  168.  
  169.   XtFree(superstrtab);
  170. }
  171.  
  172. static void SuperXmStringTable_Declare_Temporary_Storage(superstrtab, pointer, deallocator)
  173.      SuperXmStringTable superstrtab;
  174.      XtPointer          pointer;
  175.      void             (*deallocator)();
  176. {
  177.   if (superstrtab->freeables == NULL) {
  178.     superstrtab->freeables_size = FREEABLES_SIZE_INCREMENT;
  179.     superstrtab->freeables = (Deallocator_Pair *) XtMalloc((unsigned) (superstrtab->freeables_size * sizeof(struct _Deallocator_Pair)));
  180.     superstrtab->freeables_end_idx = 0;
  181.   }
  182.   else if (superstrtab->freeables_end_idx >= superstrtab->freeables_size) {
  183.     superstrtab->freeables_size += FREEABLES_SIZE_INCREMENT;
  184.     superstrtab->freeables = (Deallocator_Pair *) XtRealloc(superstrtab->freeables, (unsigned) (superstrtab->freeables_size * sizeof(struct _Deallocator_Pair)));
  185.   }
  186.  
  187.   superstrtab->freeables[superstrtab->freeables_end_idx].pointer = pointer;
  188.   superstrtab->freeables[superstrtab->freeables_end_idx].deallocator = deallocator;
  189.   ++(superstrtab->freeables_end_idx);
  190. }
  191.  
  192. SuperXmStringTable Wxms_Cvt_LispStringSequence_to_SuperXmStringTable(lisp_val)
  193.      LVAL lisp_val;
  194. {
  195.   LVAL elt;
  196.   SuperXmStringTable superstrtab;
  197.   XmString* xmstrtab;
  198.   register int xmstrtab_end_idx;
  199.   int xmstrtab_size;
  200.  
  201.   /*
  202.    * if argument is a vector, then step through array building C XmString Table.
  203.    */
  204.   if (vectorp(lisp_val)) {
  205.     xmstrtab_size = getsize(lisp_val);
  206.     superstrtab = New_SuperXmStringTable(xmstrtab_size);
  207.     xmstrtab = superstrtab->xmstrtab;
  208.     
  209.     for (xmstrtab_end_idx = 0; xmstrtab_end_idx < xmstrtab_size; xmstrtab_end_idx++) {
  210.       elt = getelement(lisp_val, xmstrtab_end_idx);
  211.       if stringp(elt)
  212.     SuperXmStringTable_Declare_Temporary_Storage(superstrtab,
  213.        (XtPointer) (xmstrtab[xmstrtab_end_idx] = XmStringCreate((char*) getstring(elt), XmSTRING_DEFAULT_CHARSET)),
  214.            XmStringFree);
  215.       else if xmstring_p(elt)
  216.     xmstrtab[xmstrtab_end_idx] = get_xmstring(elt);    /* note -- this XmString will get freed by garbage collection */
  217.       else {
  218.     Wxms_Free_SuperXmStringTable(superstrtab);    
  219.     xlerror("Bad XmStringTable element -- expected a String or an XmString.", elt);
  220.       }
  221.     }
  222.     superstrtab->xmstrtab_end_idx = xmstrtab_end_idx;
  223.     return (superstrtab);
  224.   }
  225.   /*
  226.    * if argument is a list, then cdr through list building C XmString Table.
  227.    */
  228.   else if (consp(lisp_val)) {
  229.     xmstrtab_size = XMSTRINGTABLE_SIZE_INCREMENT;
  230.     superstrtab = New_SuperXmStringTable(xmstrtab_size);
  231.     xmstrtab = superstrtab->xmstrtab;
  232.  
  233.     for (xmstrtab_end_idx = 0 ; (consp(lisp_val)) ; lisp_val = cdr(lisp_val), xmstrtab_end_idx++) {
  234.       if (xmstrtab_end_idx >= xmstrtab_size) { /* make sure it'll fit into allocated xmstrtab */
  235.     xmstrtab_size += XMSTRINGTABLE_SIZE_INCREMENT;
  236.     superstrtab->xmstrtab = xmstrtab = (XmString *) XtRealloc(xmstrtab, (unsigned) (xmstrtab_size * sizeof(XmString)));
  237.       }
  238.       elt = car(lisp_val);
  239.       if (stringp(elt))
  240.     SuperXmStringTable_Declare_Temporary_Storage(superstrtab,
  241.        (XtPointer) (xmstrtab[xmstrtab_end_idx] = XmStringCreate((char*) getstring(elt), XmSTRING_DEFAULT_CHARSET)),
  242.            XmStringFree);
  243.       else if (xmstring_p(elt))
  244.     xmstrtab[xmstrtab_end_idx] = get_xmstring(elt);    /* note -- this XmString will get freed by garbage collection */
  245.       else {
  246.     Wxms_Free_SuperXmStringTable(superstrtab);
  247.     xlerror("Bad XmStringTable element -- expected a String or an XmString.", elt);
  248.       }
  249.     }
  250.     if (lisp_val) {        /* if loop terminated due to list pointer not being a CONS cell */
  251.       Wxms_Free_SuperXmStringTable(superstrtab);    
  252.       xlerror("Bad XmStringTable list element -- expected a list of Strings or XmStrings.", lisp_val);
  253.     }
  254.     superstrtab->xmstrtab_end_idx = xmstrtab_end_idx;
  255.     return (superstrtab);
  256.   }
  257.   /*
  258.    * if argument wasn't list or vector, then error
  259.    */
  260.   else
  261.     xlerror("Bad argument type. Expected a list or vector of strings or XmStrings", lisp_val);
  262. }
  263.  
  264.  
  265. /******************************************************************************
  266.  * (XM_STRING_CREATE <string> [<charset>])
  267.  *    --> returns an XMSTRING version of string <string>.
  268.  * 
  269.  * Create a compound string from STRING <text>. Optional argument <charset>
  270.  * is a STRING specifying an XmStringCharSet. If the <charset> argument is
  271.  * ommitted, XmSTRING_DEFAULT_CHARSET is used.
  272.  *
  273.  * XmString XmStringCreate (text, charset)
  274.  *     char    *text;
  275.  *     XmStringCharSet charset;
  276.  ******************************************************************************/
  277. LVAL Wxms_Prim_XM_STRING_CREATE()
  278. {
  279.   char* string;
  280.   XmStringCharSet charset;
  281.  
  282.   string = (char*) getstring(xlgastring());
  283.   if (moreargs())
  284.     charset = (XmStringCharSet) getstring(xlgastring());
  285.   else
  286.     charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
  287.   xllastarg();
  288.   
  289.   return (cv_xmstring(XmStringCreate(string, charset)));
  290. }
  291.  
  292.  
  293. /******************************************************************************
  294.  * (XM_STRING_DIRECTION_CREATE :STRING_DIRECTION_L_TO_R)
  295.  *    --> returns an XMSTRING with a single L->R direction component.
  296.  * (XM_STRING_DIRECTION_CREATE :STRING_DIRECTION_R_TO_L)
  297.  *    --> returns an XMSTRING with a single R->L direction component
  298.  *
  299.  *
  300.  * XmString XmStringDirectionCreate (direction)
  301.  *     XmStringDirection direction;
  302.  ******************************************************************************/
  303. LVAL Wxms_Prim_XM_STRING_DIRECTION_CREATE()
  304. {
  305.   LVAL direction = xlgetarg();
  306.   xllastarg();
  307.   
  308.   if (direction == s_XmSTRING_DIRECTION_L_TO_R)
  309.     return (cv_xmstring(XmStringDirectionCreate(XmSTRING_DIRECTION_L_TO_R)));
  310.   else if (direction == s_XmSTRING_DIRECTION_R_TO_L)
  311.     return (cv_xmstring(XmStringDirectionCreate(XmSTRING_DIRECTION_R_TO_L)));
  312.   else
  313.     xlerror("Bad <direction> keyword.", direction);
  314. }
  315.  
  316.  
  317. /******************************************************************************
  318.  * (XM_STRING_SEPARATOR_CREATE)
  319.  *    --> returns an XMSTRING with a single component, a separator.
  320.  *
  321.  * XmString XmStringSeparatorCreate ()
  322.  ******************************************************************************/
  323. LVAL Wxms_Prim_XM_STRING_SEPARATOR_CREATE()
  324. {
  325.   xllastarg();
  326.   return (cv_xmstring(XmStringSeparatorCreate()));
  327. }
  328.  
  329.  
  330. /******************************************************************************
  331.  * (XM_STRING_SEGMENT_CREATE <text> [<charset>] <direction> <separator_p>)
  332.  *    --> returns a XMSTRING of the specified 
  333.  * string <text>, 
  334.  * optional string specifying character set <charset>, 
  335.  * symbol <direction>, either :STRING_DIRECTION_L_TO_R, or
  336.  *                            :STRING_DIRECTION_R_TO_L
  337.  * if <separator_p> is not NIL, a separator component will be included.
  338.  * 
  339.  
  340.  * XmString XmStringSegmentCreate (text, charset, direction, separator)
  341.  *     char          *text;
  342.  *     XmStringCharSet     charset;
  343.  *     XmStringDirection direction;
  344.  *     Boolean         separator;
  345.  ******************************************************************************/
  346. LVAL Wxms_Prim_XM_STRING_SEGMENT_CREATE()
  347. {
  348.   XmStringDirection direction;
  349.   char* text;
  350.   LVAL lval_direction, separator_p, lval_charset;
  351.   XmStringCharSet charset;
  352.  
  353.   text = (char*) getstring(xlgastring());
  354.   lval_charset = xlgetarg();
  355.   if (stringp(lval_charset)) {
  356.     charset = (XmStringCharSet) getstring(lval_charset);
  357.     lval_direction = xlgetarg();
  358.   }
  359.   else {
  360.     charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
  361.     lval_direction = lval_charset;
  362.   }
  363.   separator_p = xlgetarg();
  364.   xllastarg();
  365.  
  366.   if (lval_direction == s_XmSTRING_DIRECTION_L_TO_R)
  367.     direction = XmSTRING_DIRECTION_L_TO_R;
  368.   else if (lval_direction == s_XmSTRING_DIRECTION_R_TO_L)
  369.     direction = XmSTRING_DIRECTION_R_TO_L;
  370.   else
  371.     xlerror("Bad <direction> keyword.", lval_direction);
  372.   
  373.   return (cv_xmstring(XmStringSegmentCreate(text, charset, direction, 
  374.                         (separator_p) ? TRUE : FALSE)));
  375. }
  376.  
  377. /******************************************************************************
  378.  * (XM_STRING_CREATE_L_TO_R <text> [<charset>])
  379.  *    --> returns an XMSTRING version of string <text>.
  380.  * 
  381.  * Create a left-to-right compound string from STRING <text>. If <text>
  382.  * includes '\n', they will be replaced by a separator.
  383.  *
  384.  * Optional argument <charset> is a STRING specifying an XmStringCharSet. If the
  385.  * <charset> argument is ommitted, XmSTRING_DEFAULT_CHARSET is used.
  386.  *
  387.  * XmString XmStringCreateLtoR (text, charset)
  388.  *     char    *text;
  389.  *     XmStringCharSet charset;
  390.  ******************************************************************************/
  391. LVAL Wxms_Prim_XM_STRING_CREATE_L_TO_R()
  392. {
  393.   char* string;
  394.   XmStringCharSet charset;
  395.  
  396.   string = (char*) getstring(xlgastring());
  397.   if (moreargs())
  398.     charset = (XmStringCharSet) getstring(xlgastring());
  399.   else
  400.     charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
  401.   xllastarg();
  402.   
  403.   return (cv_xmstring(XmStringCreateLtoR(string, charset)));
  404. }
  405.  
  406.  
  407. /******************************************************************************
  408.  * XmStrings are gross! -- I'm ignoring this fn in this version of WINTERP.
  409.  * 
  410.  * Boolean XmStringInitContext (context, string)
  411.  *     XmStringContext *context;
  412.  *     XmString string;
  413.  ******************************************************************************/
  414. /******************************************************************************
  415.  * XmStrings are gross! -- I'm ignoring this fn in this version of WINTERP.
  416.  *
  417.  * void XmStringFreeContext (context)
  418.  *     XmStringContext context;
  419.  ******************************************************************************/
  420. /******************************************************************************
  421.  * XmStrings are gross! -- I'm ignoring this fn in this version of WINTERP.
  422.  *
  423.  * XmStringComponentType 
  424.  * XmStringGetNextComponent (context, text, charset, direction, 
  425.  *         unknown_tag, unknown_length, unknown_value)
  426.  *     XmStringContext     context;
  427.  *     char        **text;
  428.  *     XmStringCharSet    *charset;
  429.  *     XmStringDirection    *direction;
  430.  *     XmStringComponentType *unknown_tag;
  431.  *     UShort        *unknown_length;
  432.  *     UChar        **unknown_value;
  433.  ******************************************************************************/
  434. /******************************************************************************
  435.  * XmStrings are gross! -- I'm ignoring this fn in this version of WINTERP.
  436.  *
  437.  * XmStringComponentType XmStringPeekNextComponent (context)
  438.  *     XmStringContext    context;
  439.  ******************************************************************************/
  440. /******************************************************************************
  441.  * XmStrings are gross! -- I'm ignoring this fn in this version of WINTERP.
  442.  *
  443.  * Boolean XmStringGetNextSegment (context, text, charset, direction, separator)
  444.  *     XmStringContext     context;
  445.  *     char        **text;
  446.  *     XmStringCharSet    *charset;
  447.  *     XmStringDirection *direction;
  448.  *     Boolean        *separator;
  449.  ******************************************************************************/
  450.  
  451.  
  452. /******************************************************************************
  453.  * (XM_STRING_GET_L_TO_R <xmstring> [<charset>])
  454.  *    --> returns a STRING, or NIL if no matching character set found.
  455.  *
  456.  * This function will fetch the first text segment of the XMSTRING <xmstring>
  457.  * which matches the character set <charset>, and returns that as a STRING.
  458.  * Optional argument <charset> is a STRING specifying an XmStringCharSet.
  459.  * If the <charset> argument is ommitted, XmSTRING_DEFAULT_CHARSET is used.
  460.  *
  461.  * Boolean XmStringGetLtoR (string, charset, text)
  462.  *     XmString         string;
  463.  *     XmStringCharSet    charset;
  464.  *     char        **text;
  465.  ******************************************************************************/
  466. LVAL Wxms_Prim_XM_STRING_GET_L_TO_R()
  467. {
  468.   LVAL lval_string;
  469.   char* result;
  470.   XmStringCharSet charset;
  471.   XmString xmstring;
  472.  
  473.   xmstring = get_xmstring(xlga_xmstring());
  474.   if (moreargs())
  475.     charset = (XmStringCharSet) getstring(xlgastring());
  476.   else
  477.     charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
  478.   xllastarg();
  479.  
  480.   if (XmStringGetLtoR(xmstring, charset, &result)) {
  481. /*    
  482.     lval_string = cvstring(result);
  483.     XtFree(result);
  484. */
  485.     lval_string = cv_string(result); /* don't copy string, let XLISP-GC free it... */
  486.     return (lval_string);
  487.   }
  488.   else 
  489.     return (NIL);
  490. }
  491.  
  492.  
  493. /******************************************************************************
  494.  * XmStrings are gross! -- I'm ignoring this fn in this version of WINTERP.
  495.  *
  496.  * XmFontList XmFontListCreate (font, charset)
  497.  *     XFontStruct     *font;
  498.  *     XmStringCharSet     charset;
  499.  ******************************************************************************/
  500. /******************************************************************************
  501.  * XmStrings are gross! -- I'm ignoring this fn in this version of WINTERP.
  502.  *
  503.  * XmFontList XmStringCreateFontList (font, charset)
  504.  *     XFontStruct     *font;
  505.  *     XmStringCharSet     charset;
  506.  ******************************************************************************/
  507. /******************************************************************************
  508.  * XmStrings are gross! -- I'm ignoring this fn in this version of WINTERP.
  509.  *
  510.  * void  XmFontListFree (fontlist)
  511.  *     XmFontList fontlist;
  512.  ******************************************************************************/
  513. /******************************************************************************
  514.  * XmStrings are gross! -- I'm ignoring this fn in this version of WINTERP.
  515.  *
  516.  * XmFontList XmFontListAdd (old, font, charset)
  517.  *     XmFontList     old;
  518.  *     XFontStruct        *font;
  519.  *     XmStringCharSet    charset;
  520.  ******************************************************************************/
  521. /******************************************************************************
  522.  * XmStrings are gross! -- I'm ignoring this fn in this version of WINTERP.
  523.  *
  524.  * XmFontList XmFontListCopy (fontlist)
  525.  *     XmFontList fontlist;
  526.  ******************************************************************************/
  527.  
  528.  
  529. /******************************************************************************
  530.  * (XM_STRING_CONCAT <xmstring_a> <xmstring_b>)
  531.  *    --> returns a new XMSTRING  which is the concatenation of XMSTRINGS
  532.  *        <xmstring_a> and <xmstring_b>.
  533.  *
  534.  * XmString XmStringConcat (a, b)
  535.  *     XmString a;
  536.  *     XmString b;
  537.  ******************************************************************************/
  538. LVAL Wxms_Prim_XM_STRING_CONCAT()
  539. {
  540.   XmString xms_a = get_xmstring(xlga_xmstring());
  541.   XmString xms_b = get_xmstring(xlga_xmstring());
  542.   xllastarg();
  543.   return (cv_xmstring(XmStringConcat(xms_a, xms_b)));
  544. }
  545.  
  546.  
  547. /******************************************************************************
  548.  * I'm ignoring this one for now since it looks useless and low-level.
  549.  *
  550.  * XmString XmStringNConcat (a, b, n)
  551.  *     XmString a, b;
  552.  *     int n;
  553.  ******************************************************************************/
  554.  
  555.  
  556. /******************************************************************************
  557.  * (XM_STRING_COPY <xmstring>)
  558.  *    --> returns a new XMSTRING, a copy of <xmstring>
  559.  *
  560.  * XmString XmStringCopy (string)
  561.  *     XmString string;
  562.  ******************************************************************************/
  563. LVAL Wxms_Prim_XM_STRING_COPY()
  564. {
  565.   XmString xms = get_xmstring(xlga_xmstring());
  566.   xllastarg();
  567.   return (cv_xmstring(XmStringCopy(xms)));
  568. }
  569.  
  570.  
  571. /******************************************************************************
  572.  * I'm ignoring this one for now since it looks useless and low-level.
  573.  *
  574.  * XmString XmStringNCopy (a, n)
  575.  *     XmString a;
  576.  *     int n;
  577.  ******************************************************************************/
  578.  
  579.  
  580. /******************************************************************************
  581.  * (XM_STRING_BYTE_COMPARE <xmstring_a> <xmxtring_b>)
  582.  *    --> returns T if the two XMSTRING args are byte-for-byte equal, else
  583.  *        NIL.
  584.  *
  585.  * Note that this function will return NIL for an XMSTRING that is retrieved
  586.  * from a widget via :get_values, a callback, or a method. It's pretty useless, 
  587.  * just like all the other XmString bogosities.
  588.  *
  589.  * Boolean XmStringByteCompare (a, b)
  590.  *     XmString a, b;
  591.  ******************************************************************************/
  592. LVAL Wxms_Prim_XM_STRING_BYTE_COMPARE()
  593. {
  594.   extern LVAL true;
  595.   XmString xms_a = get_xmstring(xlga_xmstring());
  596.   XmString xms_b = get_xmstring(xlga_xmstring());
  597.   xllastarg();
  598.   return (XmStringByteCompare(xms_a, xms_b) ? true : NIL);
  599. }
  600.  
  601.  
  602. /******************************************************************************
  603.  * (XM_STRING_COMPARE <xmstring_a> <xmxtring_b>)
  604.  *    --> returns T if the two XMSTRING args are "semantically equal", 
  605.  *        else NIL.
  606.  *
  607.  * Boolean XmStringCompare (a, b)
  608.  *     XmString a, b;
  609.  ******************************************************************************/
  610. LVAL Wxms_Prim_XM_STRING_COMPARE()
  611. {
  612.   extern LVAL true;
  613.   XmString xms_a = get_xmstring(xlga_xmstring());
  614.   XmString xms_b = get_xmstring(xlga_xmstring());
  615.   xllastarg();
  616.   return (XmStringCompare(xms_a, xms_b) ? true : NIL);
  617. }
  618.  
  619.  
  620. /******************************************************************************
  621.  * (XM_STRING_LENGTH <xmstring>)
  622.  *    --> returns a FIXNUM representing the number of bytes in <xmstring>
  623.  *
  624.  * int XmStringLength (string)
  625.  *     XmString string;
  626.  ******************************************************************************/
  627. LVAL Wxms_Prim_XM_STRING_LENGTH()
  628. {
  629.   XmString xms = get_xmstring(xlga_xmstring());
  630.   xllastarg();
  631.   return (cvfixnum((FIXTYPE) XmStringLength(xms)));
  632. }
  633.  
  634.  
  635. /******************************************************************************
  636.  * (XM_STRING_EMPTY <xmstring>)
  637.  *    --> returns T if all segments in XMSTRING <xmstring> are zero length
  638.  *        or if there are no text segments. Otherwiser returns NIL.
  639.  *
  640.  * Boolean XmStringEmpty (string)
  641.  *     XmString string;
  642.  ******************************************************************************/
  643. LVAL Wxms_Prim_XM_STRING_EMPTY()
  644. {
  645.   extern LVAL true;
  646.   XmString xms = get_xmstring(xlga_xmstring());
  647.   xllastarg();
  648.   return (XmStringEmpty(xms) ? true : NIL);
  649. }
  650.  
  651. #ifdef WINTERP_MOTIF_11
  652. /******************************************************************************
  653.  * (XM_STRING_HAS_SUBSTRING <xmstring> <xmsubstring>)
  654.  *    --> returns T if <xmsubstring> is a substring of <xmstring>;
  655.  *        both argumetns are XmStrings. Otherwise, returns NIL.
  656.  *
  657.  * Boolean XmStringHasSubstring( XmString string , XmString substring );
  658.  *
  659.  ******************************************************************************/
  660. LVAL Wxms_Prim_XM_STRING_HAS_SUBSTRING()
  661. {
  662.   extern LVAL true;
  663.   XmString xmstring    = get_xmstring(xlga_xmstring());
  664.   XmString xmsubstring = get_xmstring(xlga_xmstring());
  665.   xllastarg();
  666.  
  667.   return (XmStringHasSubstring(xmstring, xmsubstring) ? true : NIL);
  668. }
  669. #endif                /* WINTERP_MOTIF_11 */
  670.  
  671.  
  672. /******************************************************************************
  673.  * Don't need to interface this -- XMSTRINGS are freed by garbage collector.
  674.  *
  675.  * void XmStringFree (string)
  676.  *     XmString string;
  677.  ******************************************************************************/
  678. /******************************************************************************
  679.  * Add this when I add the type XmFontList to winterp.
  680.  *
  681.  * Dimension XmStringBaseline (fontlist, string)
  682.  *     XmFontList fontlist;
  683.  *     XmString string;
  684.  ******************************************************************************/
  685. /******************************************************************************
  686.  * Add this when I add the type XmFontList to winterp.
  687.  *
  688.  * Dimension XmStringWidth (fontlist, string)
  689.  *     XmFontList fontlist;
  690.  *     XmString string;
  691.  ******************************************************************************/
  692. /******************************************************************************
  693.  * Add this when I add the type XmFontList to winterp.
  694.  *
  695.  * Dimension XmStringHeight (fontlist, string)
  696.  *     XmFontList fontlist;
  697.  *     XmString string;
  698.  ******************************************************************************/
  699. /******************************************************************************
  700.  * Add this when I add the type XmFontList to winterp.
  701.  *
  702.  * void XmStringExtent (fontlist, string, width, height)
  703.  *     XmFontList fontlist;
  704.  *     XmString string;
  705.  *     Dimension *width, *height;
  706.  ******************************************************************************/
  707.  
  708.  
  709. /******************************************************************************
  710.  * (XM_STRING_LINE_COUNT <xmstring>)
  711.  *    --> returns a FIXNUM representing the number of lines
  712.  *          in XMSTRING <xmstring>.
  713.  *
  714.  * int XmStringLineCount (string)
  715.  *     XmString string;
  716.  ******************************************************************************/
  717. LVAL Wxms_Prim_XM_STRING_LINE_COUNT()
  718. {
  719.   XmString xms = get_xmstring(xlga_xmstring());
  720.   xllastarg();
  721.   return (cvfixnum((FIXTYPE) XmStringLineCount(xms)));
  722. }
  723.  
  724.  
  725. /******************************************************************************
  726.  * Ignore -- too low-level.
  727.  
  728.  * void XmStringDraw (d, w, fontlist, string, gc, x, y, width, align, lay_dir, clip)
  729.  *     Display    *d;
  730.  *     Window     w;
  731.  *     XmFontList fontlist;
  732.  *     XmString    string;
  733.  *     GC        gc;
  734.  *     Position    x, y;
  735.  *     Dimension    width;
  736.  *     UChar    align;
  737.  *     UChar    lay_dir;
  738.  *     XRectangle    *clip;
  739.  ******************************************************************************/
  740. /******************************************************************************
  741.  * Ignore -- too low-level
  742.  * void XmStringDrawImage (d, w, fontlist, string, gc, x, y, 
  743.  *     width, align, lay_dir, clip)
  744.  *     Display    *d;
  745.  *     Window     w;
  746.  *     XmFontList fontlist;
  747.  *     XmString    string;
  748.  *     GC        gc;
  749.  *     Position    x, y;
  750.  *     Dimension    width;
  751.  *     UChar    align;
  752.  *     UChar    lay_dir;
  753.  *     XRectangle    *clip;
  754.  ******************************************************************************/
  755. /******************************************************************************
  756.  * Ignore -- too low-level
  757.  *
  758.  * void XmStringDrawUnderline (d, w, fontlist, string, gc, x, y, 
  759.  *     width, align, lay_dir, clip, underline)
  760.  *     Display    *d;
  761.  *     Window     w;
  762.  *     XmFontList fontlist;
  763.  *     XmString    string;
  764.  *     GC        gc;
  765.  *     Position    x, y;
  766.  *     Dimension    width;
  767.  *     UChar    align;
  768.  *     UChar    lay_dir;
  769.  *     XRectangle    *clip;
  770.  *     XmString    underline;
  771.  ******************************************************************************/
  772.  
  773.  
  774. #ifdef WINTERP_MOTIF_11
  775. /******************************************************************************
  776.  * (XM_CVT_CT_TO_XM_STRING  <STRING>)
  777.  *    --> returns an XMSTRING.
  778.  *
  779.  * "a compound string function that converts compound text to a compound string."
  780.  * <STRING> is a string...
  781.  *----------------------------------------------------------------------------
  782.  *           XmString XmCvtCTToXmString (text)
  783.  *                char        * text;
  784.  ******************************************************************************/
  785. LVAL Wxms_Prim_XM_CVT_CT_TO_XM_STRING()
  786. {
  787.   char* string = (char*) getstring(xlgastring());
  788.   xllastarg();
  789.   
  790.   return (cv_xmstring(XmCvtCTToXmString(string)));
  791. }
  792. #endif                /* WINTERP_MOTIF_11 */
  793.  
  794.  
  795. #ifdef WINTERP_MOTIF_11
  796. /******************************************************************************
  797.  * (XM_CVT_XM_STRING_TO_CT  <XMSTRING>)
  798.  *    --> returns a STRING.
  799.  *
  800.  * "a compound string function that converts a compound string to compound text."
  801.  * <XMSTRING> is an XMSTRING. 
  802.  *
  803.  *----------------------------------------------------------------------------
  804.  *           char * XmCvtXmStringToCT (string)
  805.  *                XmString    string;
  806.  ******************************************************************************/
  807. LVAL Wxms_Prim_XM_CVT_XM_STRING_TO_CT()
  808. {
  809.   XmString xmstring = get_xmstring(xlga_xmstring());
  810.   xllastarg();
  811.   
  812.   return (cv_string(XmCvtXmStringToCT(xmstring))); /* cv_string() doesn't copy string returned by XmCvtXmStringToCT()... the string will be freed by garbage collection when appropriate... */
  813. }
  814. #endif                /* WINTERP_MOTIF_11 */
  815.  
  816.  
  817. /*****************************************************************************
  818.  * Initialization proc.
  819.  ****************************************************************************/
  820. Wxms_Init()
  821. {
  822.   s_XmSTRING_DIRECTION_L_TO_R = xlenter(":STRING_DIRECTION_L_TO_R");
  823.   s_XmSTRING_DIRECTION_R_TO_L = xlenter(":STRING_DIRECTION_R_TO_L");
  824. }
  825.